package com.enjoy.redis.mq;

import org.junit.Test;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPubSub;

public class PSTest {

    @Test
    public void publish() {
        Jedis jedis = new Jedis(new HostAndPort("192.168.126.128", 6379));
        jedis.publish("bsoft", "hello world");
        System.out.println("发布成功");
    }

    @Test
    public void subscribe() {

        Jedis jedis = new Jedis(new HostAndPort("192.168.126.128", 6379));

        JedisPubSub jedisPubSub = new JedisPubSub() {
            @Override
            public void onMessage(String channel, String message) {
                System.out.println("在" + channel + "上拿到订阅消息" + message);
            }
        };

        jedis.subscribe(jedisPubSub,"bsoft");
    }
}
